using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Threading;

namespace Obsady
{
    class CListBoxLogger : ILogger
    {
        ListBox _listBox;
        public CListBoxLogger(ListBox listBox)
        {
            _listBox = listBox;
        }

        private delegate void AddListBoxItemDelegate(ListBox item);
        
                    

        public override void Log(object who,string str)
        {
            if (_listBox.InvokeRequired)
            {
                _listBox.Invoke(new MethodInvoker(delegate()
                    {
                        _listBox.Items.Add(str);
                        _listBox.SetSelected(_listBox.Items.Count - 1, true);
                        _listBox.SetSelected(_listBox.Items.Count - 1, false);
                    }));
            }
            else
            {
                _listBox.Items.Add(str);
                _listBox.SetSelected(_listBox.Items.Count - 1, true);
                _listBox.SetSelected(_listBox.Items.Count - 1, false);
            }
        }
    }
}
